package cn.dw.mm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dw.mm.domain.Department;
import cn.dw.mm.service.DepartmentService;

@Controller
@RequestMapping("/department")
public class DepartmentController {
	@Autowired
	private DepartmentService departmentService;
	
	
	@RequestMapping(value = "/level", method = RequestMethod.POST)
	@ResponseBody
	public List<Department> selectByLevel(@RequestParam("level") String level) {
		return departmentService.selectByLevel(level);
	}
	
	@RequestMapping(value = "/id", method = RequestMethod.POST)
	@ResponseBody
	public Department selectById(@RequestParam("id") Integer id) {
		return departmentService.selectById(id);
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public int update(Department department) {
		return departmentService.updateById(department);
	}
	
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	@ResponseBody
	public int deleteById(@RequestParam("id") Integer id) {
		return departmentService.deleteById(id);
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ResponseBody
	public int insert(Department department) {
		return departmentService.insert(department);
	}
}
